//给谁 json
function animate(obj, json) {
  clearInterval(obj.timer)
  obj.timer = setInterval(() => {
    var flag = true //用来判断是否停止定时器
    //计算步长 动画原理 盒子本身样式+步长
    // //我们怎么知道我们当前的样式
    // //当前样式 （target-当前样式）/10==步长
    for (const key in json) {
      var current = 0;
      if (key == "opacity") {
        current = Math.round(parseInt(getStyle(obj, "", key) * 100)) || 0
      } else {
        current = parseInt(getStyle(obj, "", key))
      }
      // current = parseInt(getStyle(obj, "", key)*100);
      var step = (json[key] - current) / 10; //步长
      step = step > 0 ? Math.ceil(step) : Math.floor(step) //取整步长

      //透明度
      if (key == "opacity") {
        if ("opacity" in obj.style) {
          obj.style.opacity = (current + step) / 100
        } else {
          obj.style.filter = "alpha(opacity=" + (current + step) + ")"
        }
      } else if (key == "zIndex") {
        obj.style.zIndex = json[key]
      } else {
        obj.style[key] = current + step + "px"
      }

      obj.style[key] = current + step + "px"
      //只要其中不满足条件 就不停止定时器
      if (current != json[key]) {
        flag = false
      }
    }
    if (flag) {//用于判断定时器的条件
      clearInterval(obj.timer)
    }

  }, 60)
}

function getStyle(ele, tum = null, attr) {
  if (window.getComputedStyle) { // 元素 伪类 css名字
    return window.getComputedStyle(ele, tum)[attr];
  }

}